package com.miaosha.miaosha.controller;

import com.miaosha.miaosha.seckill.SecKillRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Random;

@Controller
public class GoodsController {

    private SecKillRedis secKillRedis;
    @Autowired
    public void setSecKillRedis(SecKillRedis secKillRedis) {
        this.secKillRedis = secKillRedis;
    }

    @RequestMapping("/ms")
    public String ms(){

        return "index";
    }

    /**
     * 提交秒杀请求
     * @param prodid 商品id
     * @return
     */
    @PostMapping("/doseckill")
    public @ResponseBody Integer doseckill(String prodid){
        //用户id
        String userid = new Random().nextInt(50000)+"";

        return secKillRedis.doSecKill(userid,prodid);
    }
}
